<?php

/**
 * Controller for actions (in member area) of account module
 *  
 * @version 2012-10-10
 * @package account
 * @subpackage controller
 * @category Account_Controller_Member
 */

/**
 * Include common class (in all areas)
 */
require_once("global.php");
 
class Account_Controller_Member extends Account_Controller_Global
{

	/**
	* Index
	* Default function that will be used upon module start-up.
	*
	* @version 2012-10-10
	* @param Request $req
	* @return redirect
	* @access public
	*/
	function processIndex($req)
	{
		return $this->processHome($req);
	}

	/**
	* Login
	* This function displays the log-in form.
	*
	* @version 2012-12-10
	* @param Request $req
	* @return View (login page)
	* @access public
	*/
	public function processHome($req)
	{
		$view = $this->getView("member_home");
		$category = $req->getInt('category',0);
		$dbCategories = db::getModel('categories');
		$dbDataKeys = db::getModel('data_keys');
		$categories = $dbCategories->getMemberCategories($this->_accountId);
		
		$rows = $dbDataKeys->getMemberKeyList($this->_accountId,array('category_id'=>'='.$category));

		$view->setVar('categories', $categories);
		$view->setVar('category', $category);
		$view->setVar('rows', $rows);
		
		return $view;
	}

	/**
	* Logout
	* This function logs out an member user and removes "member" session.
	*
	* @param Request $req
	* @return redirect (admin login page)
	* @access public
	*/
	public function processLogout($req)
	{
		unset($_SESSION['member']);
		$req->forward("/");
	}
}